****APPENDIX TABLE D1-D2****

cd "$main_dir/output/tables/appendix_d"

global basic 	sex marital religion edu ethnicity birth_state
global extra	employment_status occupation income urban
global time 	survey_year age generation
global polit    party partisan

//--------------------------------------------------------
//Create Table D1
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_clean.dta"

gen total_obs = 1

tab sex, gen(sex_dummy)
tab religion, gen(religion_dummy)
tab edu, gen(edu_dummy)
tab marital, gen(marital_dummy)

cap drop sex_dummy1
rename sex_dummy2 male
rename sex_dummy3 female

drop religion_dummy1
rename religion_dummy2 jewish
rename religion_dummy3 christian
rename religion_dummy4 other

cap drop edu_dummy1
rename edu_dummy2 primary
rename edu_dummy3 secondary
rename edu_dummy4 tertiary

drop marital_dummy1
rename marital_dummy2 married
rename marital_dummy3 not_married

collapse (sum) total_obs (mean) trust_fed_govt trust_govt_index trust_others male female married not_married christian jewish other primary secondary tertiary, by(cohort)

drop if cohort=="" | cohort=="1850s" | cohort=="1860s" | cohort=="1870s" | cohort=="2000s"

local varlist trust_fed_govt trust_govt_index trust_others male female married not_married christian jewish other primary secondary tertiary
foreach var of local varlist {
	format `var' %5.0g
}

export delimited using "table_d1.csv", replace

//--------------------------------------------------------
//Create Table D2
//--------------------------------------------------------

clear
use "$data_dir/clean/anes_final.dta"

qui reghdfe trust_fed_govt wgrowth_rate_1 yob_ln_gdppc, absorb(state_code $time $basic $extra $polit) cluster(yob)
keep if e(sample)==1

keep trust_fed_govt trust_govt_index trust_others wgrowth_rate_1 winflation_1 wsp500return_1 wpretax_income_top10_1 wpretax_income_top1_1 wgrowth_rate_1 wunemployment_rate_1 sd_inflation wprop_unrest_1 wno_exec_changes_1 wprop_affect_epidemic_1 wbank_crisis_1 wcurrency_crisis_1 wtwin_crisis_1 fy_growth_rate preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15 wgrowth_shock_1 wdisaster_1 wacceleration_1
order trust_fed_govt trust_govt_index trust_others wgrowth_rate_1 winflation_1 wsp500return_1 wpretax_income_top10_1 wpretax_income_top1_1 wgrowth_rate_1 wunemployment_rate_1 sd_inflation wprop_unrest_1 wno_exec_changes_1 wprop_affect_epidemic_1 wbank_crisis_1 wcurrency_crisis_1 wtwin_crisis_1 fy_growth_rate preyob_growth_rate_5 preyob_growth_rate_10 preyob_growth_rate_15 wgrowth_shock_1 wdisaster_1 wacceleration_1

outreg2 using table_d2, sum(log) replace
